﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace TestApp.Flowchart.Model
{
    [JsonObject(MemberSerialization.OptIn)]
    class CircleNode : FlowNode
    {
        private int _borderThickness=1;
        [JsonProperty]
        public int BorderThickness
        {
            get { return _borderThickness; }
            set
            {
                _borderThickness = value;
                OnPropertyChanged("BorderThickness");
            }
        }

        private string _borderColor = "255, 0, 0, 0";
        [JsonProperty]
        public string BorderColor
        {
            get { return _borderColor; }
            set
            {
                _borderColor = value;
                OnPropertyChanged("BorderColor");
            }
        }
        private string _backgroundColor = "255, 255, 0, 0";
        [JsonProperty]
        public string BackgroundColor
        {
            get { return _backgroundColor; }
            set
            {
                _backgroundColor = value;
                OnPropertyChanged("BackgroundColor");
            }
        }

        public CircleNode() { }
        
        public override FrameworkElement CreateContent()
        {
            var textBlock = base.CreateContent() as TextBlock;

            var canvas = new Canvas();


            Ellipse ui = new Ellipse();

            var mySolidColorBrush = new SolidColorBrush();
            mySolidColorBrush.Color = UIUtils.convertRGB(this._borderColor);
            ui.Stroke = mySolidColorBrush;
            
            mySolidColorBrush = new SolidColorBrush();
            mySolidColorBrush.Color = UIUtils.convertRGB(this._backgroundColor);
            ui.Fill = mySolidColorBrush;
            
            ui.StrokeThickness = this._borderThickness;

            ui.Width = this.Width;
            ui.Height = this.Height;

            canvas.Children.Add(ui);


            Canvas.SetLeft(textBlock, this.Width / 2);
            Canvas.SetTop(textBlock, this.Height + 10);

            canvas.Children.Add(textBlock);

            return canvas;
        }

        public FlowNode Json2Obj(string value)
        {
            return JSONUtils.Json2Obj<CircleNode>(value);
        }
    }
}
